<!DOCTYPE html>
<html>
<title>Sign Up</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="./css/w3.css">
<script src="https://cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script>
if(!AV.applicationId)
{
AV.init({
  appId: 'hqD9IMTNsFSk2LxbiFnBEvCp-gzGzoHsz',
  appKey: 'ITs4Ni1EiEI5sEcQQ4CBJqpb'
});
}
function ele(id)
{
	return document.getElementById(id);
}
function sendSMS()
{
AV.Cloud.requestSmsCode('18939895003').then(function (success) {
   console.log("sendSMS ok");
  }, function (error) {
  
  console.log("sendSMS error:" + error.message);
  });
}
function verifySMS()
{
  AV.User.signUpOrlogInWithMobilePhone('18939895003', '123456').then(function (success) {
    // 成功
  }, function (error) {
    // 失败
  });
}
function showErrors(message)
{
ele("errormsg").innerHTML = message;
}
function regUser(e)
{
  if(e)
  {
      e.innerText = "正在注册...";
      e.disabled = true;
  }
  // 新建 AVUser 对象实例
  var user = new AV.User();
  // 设置用户名
  user.setUsername(document.getElementById("name").value);
  // 设置密码
  user.setPassword(document.getElementById("password").value);
  // 设置邮箱
  user.setEmail(document.getElementById("email").value);
  user.setMobilePhoneNumber(document.getElementById("name").value);
  user.signUp().then(function (loggedInUser) {
      console.log(loggedInUser);
	  window.location.href="login.html";
  }, function (error) {
  if(e)
  {
      e.innerText = "注册";
      e.disabled = false;
  }
  showErrors(error.message);
  });
}

</script>
<body>
<div class="w3-content w3-container w3-card-2">
<header class="w3-container w3-teal">
  <h1>Sign Up</h1>
</header>
<div class="w3-container w3-half w3-margin-top">
<img class="w3-image" src="./img/man2.jpg">
</div>
<div class="w3-container w3-half w3-margin-top">

<p>
<label>Name:</label>
<input id="name" class="w3-input" type="text" style="width:90%" required>
</p>
<p>
<label>Password:</label>
<input id="password" class="w3-input" type="password" style="width:90%" required>
</p>
<p>
<label>Email:</label>
<input id="email" class="w3-input" type="text" style="width:90%" required>
</p>


<p>
<button class="w3-button w3-section w3-teal w3-ripple" onclick="regUser(this)"> 注册 </button>
<a href="login.html">登录</a>
</p>
<p class="w3-text-red" id="errormsg">

</p>
</div>
</div>

</body>
</html> 